package com.kevin.design.structuralPattern.decorator;

public class DecoratorOfSwing{
    public static void main(String[] args) {
        Function function = new FlyFunction();
        function = new LoveFunction(function);
        function = new MakeFunction(function);
        function.display();
    }
}

abstract class Function{
    public abstract void display();
}

class FlyFunction extends Function{

    @Override
    public void display() {
        System.out.println("我有飞行功能！");
    }
}

class PlayFunction extends Function{

    @Override
    public void display() {
        System.out.println("我有玩的功能！");
    }
}

abstract class FunctionDecorator extends Function{
    private Function function;

    public FunctionDecorator(Function function) {
        this.function = function;
    }

    @Override
    public void display() {
        function.display();
    }
}

class LoveFunction extends FunctionDecorator{
    public LoveFunction(Function function) {
        super(function);
    }

    @Override
    public void display() {
        super.display();
        setFunction();
    }

    public void setFunction(){
        System.out.println("我有爱的功能");
    }
}

class MakeFunction extends FunctionDecorator{

    public MakeFunction(Function function) {
        super(function);
    }

    @Override
    public void display() {
        super.display();
        setFunction();
    }

    public void setFunction(){
        System.out.println("我有做的功能");
    }
}